/************************************************************************/
/*  									*/
/*  writecdwd_MSE.c							*/
/*									*/
/*  Tom Lookabaugh							*/
/*  August 14, 1987							*/
/*  Last Revision: August 14, 1987					*/
/*									*/
/*  DESCRIPTION								*/
/*	Writes a codeword.						*/
/*  RETURNS								*/
/*	No significant value.  						*/
/*  CALLS								*/
/*	error()								*/
/*									*/
/************************************************************************/

#include "stdvq.h"

writecdwd (cdbk, cdwd, dist, tsvect, cdbksz, outfile) 

    double *cdbk;	/* codebook					*/
    int cdwd;		/* index of desired codeword			*/
    double dist;	/* distortion to closest codeword		*/
    double* tsvect;     /* current test sequence vector                 */
    int cdbksz;		/* size of codebook				*/
    FILE *outfile;	/* reproductions file				*/
    
{

   int i;
   DATATYPE out;
   DATATYPE round_float(); 
   
   for (i = 0; i < cdbkdim; i++) {
      out = round_float(cdbk[cdwd*cdbkdim + i]);
      if (fwrite(&out, sizeof(DATATYPE), 1, outfile) != 1)
        error("failed to write codeword (writecdwd 1)");
   }


}


short round_short (x)
double x;
{
    short r;
    if (x - (r = (short) x) > 0.5) r++;
    return(r);
}

float round_float (x)
double x;
{
    return ((float) x);
}

double round_double (x)
double x;
{
    return (x);
}
